package cn.hughie.str;

/**
 * @Author yuh
 * @Date Created in 下午2:45 2018/5/19
 * @Description 显示回退暴力匹配字符串
 */
public class SubStr {

    public static int indexOf(String pat, String txt) {
        int pl = pat.length();
        int tl = txt.length();

        int j = 0,i = 0;
        for (; i < tl && j < pl; i++) {
            if(pat.charAt(j) == txt.charAt(i)){
                j ++;
            }else{
                i -= j;
                j = 0;
            }
        }
        if(j == pl){
            return i - pl;
        }else{
            return i;
        }
    }

    public static void main(String[] args) {
        int i = indexOf("abbb", "aabbbbbbbbbbds");
        System.out.println(i);
    }
}
